int maxProfit(int prices[], int n) {       	 	 
    int i, total = 0, lastmax = 0, newmax = 0;
    for (i = 1 ; i < n ; i++) {       	 	 
        newmax += (prices[i] - prices[i-1]);
        if (newmax > 0 && newmax > lastmax) {       	 	 
            lastmax = newmax;
        } else {       	 	 
            total += lastmax;
            newmax = 0;
            lastmax = 0;
        }
    }
    total += lastmax;
    return total;
}       	 	 

int main(int argc, char **argv)
{       	 	 
    int  array[128];
    int n,i;
    printf("Please input the array size\n");
    scanf("%d",&n);
    for(i=0; i < n; i++)
    {       	 	 
        printf("Please input the %d-th number\n",i);
        scanf("%d",&array[i]);
    }
    int sum = maxProfit(array, n);
    printf("the maxProfit is %d\n",sum );

}